import { createApp } from 'vue'
import App from './App.vue'

const app = createApp(App)

// 引入echats
import ECharts from 'vue-echarts'

// 引入element-ui
import ElementPlus from 'element-plus';
import 'element-plus/theme-chalk/index.css'

import { Star, Service, Monitor, PieChart, Aim, Bell, MuteNotification, Pointer, StarFilled, Compass, Tickets, Delete, Edit, Fold, Expand, ArrowDownBold, ArrowUpBold, Download, Plus, Management, HomeFilled, User, CircleCheck, Check, Comment, Grid, Crop, Position, Histogram, Avatar, HelpFilled, PictureFilled } from '@element-plus/icons-vue'

app.component("Delete", Delete)
app.component('Service', Service)
app.component('Star', Star)
app.component('Edit', Edit)
app.component('Download', Download)
app.component('Management', Management)
app.component('HomeFilled', HomeFilled)
app.component('User', User)
app.component('CircleCheck', CircleCheck)
app.component('Check', Check)
app.component('Comment', Comment)
app.component('Grid', Grid)
app.component('Crop', Crop)
app.component('Plus', Plus)
app.component('Position', Position)
app.component('Histogram', Histogram)
app.component('Avatar', Avatar)
app.component('HelpFilled', HelpFilled),
    app.component('PictureFilled', PictureFilled)
app.component('Expand', Expand)
app.component('Fold', Fold)
app.component('ArrowDownBold', ArrowDownBold)
app.component('ArrowUpBold', ArrowUpBold)
app.component('Aim', Aim)
app.component('Bell', Bell)
app.component('Compass', Compass)
app.component('Tickets', Tickets)
app.component('MuteNotification', MuteNotification)
app.component('Pointer', Pointer)
app.component('StarFilled', StarFilled)
app.component('PieChart', PieChart)
app.component('Monitor', Monitor)


// vuex
import store from './store/index.ts'

// // 引入axios
import axios from 'axios'
app.config.globalProperties.$http = axios;

//引入router
import router from './router/router'
// 引入外部变量
import basicUrl from '/public/static/db.baseUrl.ts'

app.config.globalProperties.baseUrl = basicUrl.dev_baseUrl;
app.config.globalProperties.MapAk = basicUrl.MapAk;
app.config.globalProperties.SocketUrl = basicUrl.SocketUrl;

app.component('v-chart', ECharts)
app.use(router);
app.use(store);
app.use(ElementPlus);
app.mount('#app');

app.config.globalProperties.isCollapse = true;

// 请求拦截
axios.interceptors.request.use((config) => {
    // if(store.state.Token){ 
    config.Token = store.state.Token
    config.headers.accessToken = store.state.Token
    // }
    return config;
})

axios.interceptors.response.use(res => {
    return res;
},
    err => {
        console.error(err);
        console.error("报错了");
        // router.push("/login")
    })

// 路由守卫
// router.beforeEach((to, from, next) => {
//     try {
//         if (store.state.UserMessage == null) {
//             if (to.path == "/login") {
//                 next();
//             } else if (to.path == '/register') {
//                 next();
//             } else {
//                 next('/login');
//             }
//         } else {
//             next();
//         }
//     } catch (e) {
//         next('/login');
//     }
// })